package me.imli.app.util;

import me.imli.app.App;
import me.imli.app.R;
import me.imli.app.ui.BaseActivity;
import me.imli.app.ui.MainActivity;
import me.imli.app.ui.MainActivity_;
import me.imli.app.ui.SettingActivity;
import me.imli.app.ui.SettingActivity_;
import android.content.Context;
import android.content.Intent;

public class ThemeUtil {
	
	private static final String APP_THEME = "app_theme";

	public static final int THEME_ID_BULE = R.style.AppThemeBlue;
	public static final int THEME_ID_NIGHT = R.style.AppThemeNight;
	
	public static final int THEME_BULE = 0x00000001;
	public static final int THEME_NIGHT = 0x10000000;
	
	
	public static void changeTheme(BaseActivity activity, int theme) {
		SharedPrefUtil.putInt(activity, APP_THEME, theme);
		if (activity instanceof MainActivity) {
		} else if (activity instanceof SettingActivity) {
			ActivityUtil.remove(activity);
			ActivityUtil.finishAll();
			Intent intent1 = new Intent(activity, MainActivity_.class);
			Intent intent2 = new Intent(activity, SettingActivity_.class);
			Intent[] intents = new Intent[]{intent1, intent2};
			for (int i = 0; i < intents.length; i++) {
				activity.startActivity(intents[i]);
			}
			activity.overridePendingTransition(0, 0);
			activity.finish();
		}
	}
	
	public static int getThemeId() {
		return getThemeId(getCurTheme());
	}
	
	public static int getThemeId(int theme) {
		switch (theme) {
		case THEME_BULE:
			return THEME_ID_BULE;
		case THEME_NIGHT:
			return THEME_ID_NIGHT;
		default:
			return THEME_ID_BULE;
		}
	}
	
	public static int getCurTheme() {
		return SharedPrefUtil.getInt(App.getContext(), APP_THEME, THEME_BULE);
	}
	
}
